% Normalization
SizeDataTraining = size(AllDataTraining, 1);
SizeDataTesting = size(AllDataTesting, 1);

AllData = [AllDataTraining; AllDataTesting];
PositiveOnly = true;
[AllData] = Ddavid_normalization(AllData, PositiveOnly);
AllDataTraining = AllData(1:SizeDataTraining, :);
AllDataTesting = AllData((SizeDataTraining + 1):(SizeDataTraining + SizeDataTesting), :);

% Sampling training and testing
SizeDataTraining = 3000;
[AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting, AllDataSampler] = Ddavid_sample_training_testing(AllData, TrueLabel, SizeDataTraining);

% Sampling incomplete labels
SampledDataSize = 300;
SampledLabelSize = 3;

[SampledTrueLabelTraining, SampledDataTraining, SampledOnlyTrueLabelTraining, UnSampledDataTraining, DataSampler] = Ddavid_sample_label(AllDataTraining, TrueLabelTraining, SampledDataSize, SampledLabelSize);
AllData = [AllDataTraining; AllDataTesting];
TrueLabel = [TrueLabelTraining; TrueLabelTesting];



% Get distribution features
K = 5;
KL = 1;
[DistributionFeatures] = Ddavid_get_distribution_features(AllDataTraining, AllDataTesting, SampledTrueLabelTraining, DataSampler, K, KL);

% Use distribution features
FeatureUsingList = [0 0 0];
[AllDataTraining2, AllDataTesting2, SampledDataTraining2, UnSampledDataTraining2] = Ddavid_use_distribution_features(AllDataTraining, AllDataTesting, DataSampler, DistributionFeatures, FeatureUsingList);

% Cross validation MLR_GL to find parameters
NFold = 10;
CMin = 1.0;
CMax = 10000.0;
CStep = 10.0;
etaMin = 2.0;
etaMax = 6250.0;
etaStep = 5.0;
Msg = true;
[CBest, etaBest, ResultCVBest, CSecondBest, etaSecondBest, ResultCVSecondBest] = Ddavid_MLR_GL_find_parameter_by_cross_validation(SampledDataTraining2, UnSampledDataTraining2, SampledOnlyTrueLabelTraining, CMin, CMax, CStep, etaMin, etaMax, etaStep, NFold, Msg);

% MLR_GL
[ResultBest] = Ddavid_MLR_GL(AllDataTraining2, AllDataTesting2, SampledTrueLabelTraining, TrueLabelTesting, CBest, etaBest);
[ResultSecondBest] = Ddavid_MLR_GL(AllDataTraining2, AllDataTesting2, SampledTrueLabelTraining, TrueLabelTesting, CSecondBest, etaSecondBest);
